# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# from AUR - adapted to our style.
#
# Maintainer: Carl Smedstad <carl.smedstad at protonmail dot com>
# Contributor: solnce <echo c29sbmNlQHJhdGFqY3phay5vbmU= | base64 -d>
# Contributor: Guillaume ALAUX <guillaume@archlinux.org>

pkgname=swt
pkgver=4.31
pkgrel=1
_date=202402290520
pkgdesc='An open source widget toolkit for Java.'
arch=('x86_64')
url='https://www.eclipse.org/swt/'
license=('EPL')
depends=('java-runtime>=17' 'libxtst')
makedepends=('ant' 'glu' 'gtk3' 'gtk4' 'pkgconfig' 'unzip' 'webkit2gtk')
optdepends=('glu' 'gtk3' 'gtk4')
_archive="$pkgname-$pkgver-gtk-linux-$arch.zip"
source=("https://download.eclipse.org/eclipse/downloads/drops4/R-$pkgver-$_date/$_archive"
        'build-swt.xml')
noextract=("$_archive")
sha512sums=('da61610ce00fc46893ec3ee6d5d7ed5cc59312002c6946a3748cff1a776af75bad0026512b412ef1622ca0bee124764ed8ee7f5f87364cff945b296feb86e74b'
            '4fb681c8ff716fc7223331bae98b8c8c2ae1d7f7a9738b210f4ca673f0995b9f0463c97b40d84a2db6b4d3f8f583cb3baa05c4694e796b0e1e32e831fdda3116')

prepare() {
  unzip -oq "$_archive" -d "$pkgname-$pkgver"

  cd "$pkgname-$pkgver"

  unzip -oq src.zip

  sed -i 's/-fPIC/& -Wno-error=deprecated-declarations/' library/build.sh
}

build() {
  cd "$pkgname-$pkgver"

  cp $srcdir/build-swt.xml .

  export JAVA_HOME=/usr/lib/jvm/$(archlinux-java get)
  export SWT_JAVA_HOME=${JAVA_HOME}

  ant -f build-swt.xml compile
  ant -f build-swt.xml jar
}

package() {
  cd "$pkgname-$pkgver"

  # SWT jar
  install -Dm644 swt.jar "$pkgdir/usr/share/java/swt-$pkgver.jar"
  ln -s "swt-$pkgver.jar" "$pkgdir/usr/share/java/swt.jar"

  # Shared objects
  install -d "$pkgdir/usr/lib"
  OUTPUT_DIR="$pkgdir/usr/lib" ./library/build.sh -gtk-all install
}

